<template>
    <div class="module-name  pl10 pr10 ">
        <avue-crud v-model="dialogForm" :table-loading="loading" :data="data" :option="option" :page.sync="page"
                   @on-load="onLoad"
                   @search-change="handleSearchChange"
                   @row-save="handleSave"
                   @row-update="handleUpdate"
                   @row-del="handleDel"
                   @cell-click="onCellClick"
                   :search.sync="searchForm">
        </avue-crud>
    </div>
</template>
<script>
import page from "@/mixins/page";

export default {
    name: "module-name",
    mixins: [page],
    data() {
        return {
            //分页参数
            searchForm: {
                type: 1,//错误日志
            },
            urls: {
                0: 'log',
                1: 'findAll',
            },

            data: [],
            option: {
                ...window.avueCrud,
                addBtn: false,
                viewBtn: true,
                delBtn: true,
                editBtn: false,
                // 列设置
                // clearExclude: ["schoolName"], //搜索不清空
                column: [
                    {
                        label: 'id',
                        prop: 'id',
                        search: false,
                        width: '50',
                        display: false,
                    },
                    {
                        label: 'name',
                        prop: 'name',
                        search: true,
                        width: '100',
                        searchSpan: 6,
                    },
                    {
                        label: '用户标识',
                        prop: 'userFlag',
                        width: '90',
                    },
                    // {
                    //     label: '状态码',
                    //     prop: 'status',
                    //     search: true,
                    //     searchSpan: 6,
                    //     width: '60',
                    // },
                    {
                        label: '请求ip',
                        prop: 'ip',
                        width: '130',
                    },
                    {
                        label: '请求方法',
                        prop: 'method',
                        width: '80',
                    },
                    {
                        label: '路径',
                        prop: 'path',
                        // width: '300',
                    },
                    {
                        label: '参数',
                        prop: 'arguments',
                        // width: '300',
                    },
                    // {
                    //     label: 'message',
                    //     prop: 'message',
                    //     width: '300',
                    // },
                    {
                        label: '创建时间',
                        prop: 'createAt',
                        display: false,
                        width: '130',
                    },
                    {
                        label: '创建时间',
                        prop: 'createAt',
                        display: false,
                        width: '130',
                    },
                ],
            },
            dialogForm: {},
        };
    },
    methods: {
        async handleUpdate(row, index, done) {
            const {code} = await this.$api.svipAccount.update(row.id, {
                bduss: row.bduss,
                name: row.name,
                isUsing: row.isUsing,
                stoken: row.stoken,
                status: row.status,
                isLose: row.isLose
            })
            if (code === 200) {
                this.getData(this.searchForm)
                this.$notify({
                    message: '更改成功',
                    type: 'success',
                    duration: 2000,
                })
            }
            done()
        },

        async handleSave(row, done) {
            const {code, msg} = await this.$api.svipAccount.create({
                bduss: row.bduss,
                name: row.name,
                isUsing: row.isUsing,
                stoken: row.stoken,
                status: row.status,
            })
            if (code === 200) {
                this.getData(this.searchForm)
                this.$notify({
                    message: msg || '创建成功',
                    type: 'success',
                    duration: 2000,
                })
            }
            done()
        },

        async handleDel(row) {
            this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                })
                .then(async () => {
                    const {code} = await this.$api.log.remove(row.id)
                    if (code === 200) {
                        this.getData(this.searchForm)
                        this.$notify({
                            message: '删除成功',
                            type: 'success',
                            duration: 2000,
                        })
                    }
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除',
                    })
                })
        },

    }
};
</script>

<style lang="scss" scoped>
.module-name {
}
</style>
